package com.ja.planclass.mapper;

import com.ja.planclass.model.PlanClassSelectVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by 86151 on 2019/4/24.
 */
public class PlanClassMapperImpl {
   public String queryPlanClassByCodeList(@Param("codes") List<String> codeList){
       return new SQL() {{
           SELECT("t.id,t.name,t.remark,t.code,t.status");
           FROM("planclass t ");
           StringBuffer userPlaceHolder = new StringBuffer();
           for (String code : codeList) {
               userPlaceHolder.append(code + ",");
           }
           System.out.println("处理前的数据=="+userPlaceHolder);
           userPlaceHolder.setLength(Math.max(userPlaceHolder.length() - 1, 0));
           System.out.println("处理后的数据=="+userPlaceHolder);
           WHERE("t.code in (" + userPlaceHolder + ")");
       }}.toString();
   }

    public String queryPageTest(final PlanClassSelectVo planClassSelectVo) {
        return new SQL() {{
            SELECT("code,name,remark,status");
            FROM("planclass1");
            if (!StringUtils.isEmpty(planClassSelectVo.getName())) {
                WHERE("name like CONCAT('%',#{name},'%')");
            }
            if (!StringUtils.isEmpty(planClassSelectVo.getCode())) {
                WHERE("code like CONCAT('%',#{code},'%')");
            }
            if (!StringUtils.isEmpty(planClassSelectVo.getStatus())) {
                WHERE("status=#{status}");
            }
        }}.toString();
    }
}
